<template>
  <div>

  <el-table
    :data="tableData"
    border
    style="width: 100%">
    <el-table-column
      fixed
      prop="bookname"
      label="书名">
    </el-table-column>
    <el-table-column
      prop="typename"
      label="书籍类型">
    </el-table-column>
    <el-table-column
      prop="author"
      label="作者">
    </el-table-column>
    <el-table-column
      prop="info"
      label="介绍">
    </el-table-column>
    <el-table-column
      prop="publisher"
      label="出版社">
    </el-table-column>
    <el-table-column
      prop="count"
      label="库存">
    </el-table-column>
    <el-table-column
      prop="buyprice"
      label="售价">
    </el-table-column>
    <el-table-column
      prop="status"
      label="状态">
    </el-table-column>
    <el-table-column
      fixed="right"
      label="操作">
      <template #default="scope">
        <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
        <el-button type="text" size="small">编辑</el-button>
      </template>
    </el-table-column>
  </el-table>
    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage4"
      :page-sizes="[5, 10, 20, 30]"
      :page-size="5"
      layout="total, sizes, prev, pager, next, jumper"
      :total="page.total">
    </el-pagination>
  </div>
</template>
<script>
  import qs from 'qs'
  export default {
    methods: {
      //分页
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
        this.page.pagesize = val;
        this.findBook()
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        this.page.currentPage = val;
        this.findBook()
      },

      handleClick(row) {
        console.log(row);
      },
      findBook(){
        this.$axios({
          method:'post',
          url:'t-book/findBookAndType',
          data:qs.stringify(this.page)
        }).then(res=>{
          this.tableData = res.data.data.list;
          this.page.total = res.data.data.total
        })
      }
    },
    created(){
      this.findBook()
    },

    data() {
      return {
        tableData: [],
        //分页
        page:{
          currentPage4: 1,
          //分页
          /*总条数*/
          total: 0,
          /*第几页*/
          currentPage: 1,
          /*一页显示多少条*/
          pagesize: 5,
        }
      }
    }
  }
</script>
